package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.YunjiayiMedicine;
import java.util.List;

import com.ujs.edu.medicine.dataobject.YunjiayiPost;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface YunjiayiMedicineMapper {
    @Delete({
        "delete from yunjiayi_medicine",
        "where medicine_id = #{medicineId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer medicineId);

    @Insert({
        "insert into yunjiayi_medicine (medicine_id, mename, ",
        "price, description, ",
        "mainImg, repository_num, ",
        "otherImg, prescription, ",
        "kind, pictureId)",
        "values (#{medicineId,jdbcType=INTEGER}, #{mename,jdbcType=VARCHAR}, ",
        "#{price,jdbcType=DOUBLE}, #{description,jdbcType=VARCHAR}, ",
        "#{mainimg,jdbcType=VARCHAR}, #{repositoryNum,jdbcType=INTEGER}, ",
        "#{otherimg,jdbcType=VARCHAR}, #{prescription,jdbcType=INTEGER}, ",
        "#{kind,jdbcType=INTEGER}, #{pictureid,jdbcType=INTEGER})"
    })
    @Options(useGeneratedKeys = true,keyColumn = "medicine_id",keyProperty = "medicineId")
    int insert(YunjiayiMedicine record);

    @Select({
        "select",
        "medicine_id, mename, price, description, mainImg, repository_num, otherImg, ",
        "prescription, kind, pictureId",
        "from yunjiayi_medicine",
        "where medicine_id = #{medicineId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="medicine_id", property="medicineId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="mename", property="mename", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.DOUBLE),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="mainImg", property="mainimg", jdbcType=JdbcType.VARCHAR),
        @Result(column="repository_num", property="repositoryNum", jdbcType=JdbcType.INTEGER),
        @Result(column="otherImg", property="otherimg", jdbcType=JdbcType.VARCHAR),
        @Result(column="prescription", property="prescription", jdbcType=JdbcType.INTEGER),
        @Result(column="kind", property="kind", jdbcType=JdbcType.INTEGER),
        @Result(column="pictureId", property="pictureid", jdbcType=JdbcType.INTEGER)
    })
    YunjiayiMedicine selectByPrimaryKey(Integer medicineId);

    @Select({
        "select",
        "medicine_id, mename, price, description, mainImg, repository_num, otherImg, ",
        "prescription, kind, pictureId",
        "from yunjiayi_medicine"
    })
    @Results(id = "medicineMap",value = {
        @Result(column="medicine_id", property="medicineId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="mename", property="mename", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.DOUBLE),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="mainImg", property="mainimg", jdbcType=JdbcType.VARCHAR),
        @Result(column="repository_num", property="repositoryNum", jdbcType=JdbcType.INTEGER),
        @Result(column="otherImg", property="otherimg", jdbcType=JdbcType.VARCHAR),
        @Result(column="prescription", property="prescription", jdbcType=JdbcType.INTEGER),
        @Result(column="kind", property="kind", jdbcType=JdbcType.INTEGER),
        @Result(column="pictureId", property="pictureid", jdbcType=JdbcType.INTEGER)
    })
    List<YunjiayiMedicine> selectAll();


    /*模糊查询*/
    @Select("select * from yunjiayi_medicine where mename like '%${mename}%'")
    @ResultMap("medicineMap")
    List<YunjiayiMedicine> selectLike(@Param("mename")String mename);

    /*通过名称查询*/
    @Select("select * from yunjiayi_medicine where mename=#{mename}")
    YunjiayiMedicine selectByName(@Param("mename") String mename);

    @Update({
        "update yunjiayi_medicine",
        "set mename = #{mename,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=DOUBLE},",
          "description = #{description,jdbcType=VARCHAR},",
          "mainImg = #{mainimg,jdbcType=VARCHAR},",
          "repository_num = #{repositoryNum,jdbcType=INTEGER},",
          "otherImg = #{otherimg,jdbcType=VARCHAR},",
          "prescription = #{prescription,jdbcType=INTEGER},",
          "kind = #{kind,jdbcType=INTEGER},",
          "pictureId = #{pictureid,jdbcType=INTEGER}",
        "where medicine_id = #{medicineId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(YunjiayiMedicine record);
}